import {isPlainObject} from './util';

export function transformRequest (data: any): any {
  if (isPlainObject(data)) {
    return JSON.stringify(data);
  }

  return data;
}

export function transformResponse (data: any): any {
  if (typeof data === 'string') {
    try {
      data = JSON.parse(data)
    } catch (e) {
      throw new Error(`The json parsing gets error.`);
    }
  }

  return data;
}